<?php
/**
 * The following are convenience functions I use to quickly dump variables
 * and eventually I'm sure there will be other utilities in here too
 */
function pr($var) {

    $type = gettype($var);
    switch($type) {
        case "string":
        case "integer":
            // returns the length of the string (or integer)
            $size = strlen($var);
            break;
        case "double":
            // returns whole and part lengths
            $parts = explode(".", $var);
            $size = strlen($parts[0]) . ", " . strlen($parts[1]);
        case "array":    
        case "object":
        default:
            $size = count($var);
            break;
    }
    ob_start();
    echo "<pre>";
    echo "Type: " . $type . "\n";
    echo "Size: " . $size . "\n";
    echo "Value: \n";
    var_dump($var);
    echo "</pre>";
    echo ob_get_clean();

}

function pre($var) {

    pr($var);
    exit;

}
/**
 * Define the autoload function so that classes get loaded automatically in testing
 * I may eventually try to work out some type of autoload solution in the library but im not sure
 * of the implications as of yet.
 */
function __autoload($className) {
    $paths = explode(PATH_SEPARATOR, get_include_path());
    foreach ($paths as $path) {
        $fileName = str_replace("_", DIRECTORY_SEPARATOR, $className);
        if($exists = !class_exists($className) && file_exists($class = $path.DIRECTORY_SEPARATOR.$fileName.'.php')) {
            require_once $class;
        } elseif(!$exists) {
            //eval('class '.$className.' extends Exception {}');
            //throw new $className('[__autoload] this file doesn\'t exist: '.$class);
        }
    }
}